<?php
/**
 * 标签页
 *
 */
class GoodsAction extends BaseAction {
    public function index(){
		$database_goods = D('Goods');
		
		//$category_list = $database_Category->order('`cid` ASC,`pid` ASC')->select();
		//$category_list=$database_Category->query('SELECT * FROM ic_Category');
		$category_list=$database_goods->select();
		$this->assign('goods_list',$goods_list);
		//$category_list="sss";
		//dump($category_list);
		$this->display();
	}
	public function add(){
		$this->display();
	}
	public function modify(){
		$database_goods = D('Goods');
			
		if($database_goods->data($_POST)->add()){
			$this->success('增加成功！');
		}else{
			$this->error('增加失败！');
		}
	}
	public function edit(){
		$database_hot_tag = D('Goods');
		$condition_hot_tag['cid'] = $this->_get('cid');
		$category = $database_hot_tag->where($condition_hot_tag)->find();
		$this->assign('category',$category);
		
		$this->display();
	}
	public function amend(){
		$database_hot_tag = D('Goods');
			
		if($database_hot_tag->data($_POST)->save()){
			$this->success('修改成功！');
		}else{
			$this->error('修改失败！');
		}
	}
	public function del(){
		$database_category = D('Goods');
		$condition_category['cid'] = $this->_get('cid');
		dump( $condition_category['cid']);
		if(!empty($condition_category['cid']) && $database_category->where($condition_category)->delete()){
			$this->success('删除成功！');
		}else{
			$this->error('删除失败！');
		}
	}
	
	
	public function addto(){
		if($this->isPost()){// echo "123";
			//$data_goods['goods_id']=$this->_post('cat_id');
			$data_goods['cat_id']=$this->_post('cat_id');
			$data_goods['goods_sn']=$this->_post('goods_sn');
			$data_goods['goods_name']=$this->_post('goods_name');
			//$data_goods['goods_name_style']=$this->_post('cat_id');
			$data_goods['provider_name']="provider_name_default";
			$data_goods['goods_number']=$this->_post('goods_number');
			//$data_goods['goods_weight']=$this->_post('cat_id');
			$data_goods['market_price']=$this->_post('market_price');
			$data_goods['shop_price']=$this->_post('shop_price');
			$data_goods['promote_price']=$this->_post('promote_price');
			//promote_start_date   promote_end_date warn_number
			
			$data_goods['keywords']="keywords";
			$data_goods['goods_brief']="goods_brief";
			$data_goods['goods_desc']=$this->_post('goods_desc');
			$data_goods['goods_thumb']="goods_thumb";
			$data_goods['goods_img']="goods_img";
			$data_goods['original_img']="original_img";//$this->_post('original_img');
			$data_goods['is_real']="1";
			
			$data_goods['extension_code']="extension_code";
			$data_goods['seller_note']="seller_note";
			$data_goods['is_hot']=$this->_post('is_hot');
			$data_goods['is_new']=$this->_post('is_new');
			
			//$data_new['content'] = $this->_post('content','htmlspecialchars,nl2br,stripslashes,trim');
			
			//add_time
			$data_goods['add_time']= $_SERVER['REQUEST_TIME'];
			
			//$data_new['uid'] = $_SESSION['user']['uid'] ? $_SESSION['user']['uid'] : 1;
			//$data_new['ip'] = ip2long($_SERVER['REMOTE_ADDR']);
			//$data_new['time'] = $_SERVER['REQUEST_TIME'];
			$database_goods = D('Goods');
			//dump($data_goods);
			if($vo = $database_goods->data($data_goods)->add()){
				$this->assign('goods_id',$vo);
				//$this->display();
				//设置成功后跳转页面的地址，默认的返回页面是$_SERVER['HTTP_REFERER']
			$this->success('新增成功', U('Goods/index'));
			//U('Goods/index')
			}else{
				$this->error('发布失败！');
			}
		}else{
			$this->error('非法访问！');
		}
	}
	
	public function findTypeId($cat_id){
		$Goods = M('Goods');
		$Goods->where('cat_id=$cat_id')->select();
        //$Goods->find($cat_id);
		//$User->where('type=1 AND status=1')->select(); 

		$this->display();
	}
}